import { useReactive } from "ahooks";
import { useModel } from "umi";
import { useEffect } from "react";
import compress from "gql-compress";

const useDeleteCategory = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        deleteCategoryLoading: false,
        categories: [],
    });

    const deleteCategory = async (ccUuid, callback) => {
        let query = ``;
        let res = await graphqlFetch({ query, variables: {} });
        if (res === null) return;
        if (res?.a?.totalCount === 0) {
            query = ``;
            res = await graphqlFetch({ query, variables: {} });
            if (res === null) return;
            message.success("成功删除品类信息");
            callback && callback();
        } else {
            message.warning("该品类下包含商品信息，不能删除");
        }
    };
    return { deleteCategory };
};

const query = compress(``);

export default useDeleteCategory;
